home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / System 7.0 Samples / CShell⁄THINK C / IdleTasks.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-20  |  3.6 KB  |  169 lines  |  [TEXT/MPS ]

  1. /*
  2. * Apple Macintosh Developer Technical Support
  3. **
  4. ** Program:        CShell
  5. ** File:        idletasks.c
  6. ** Written by:  Eric Soldan
  7. **
  8. ** Copyright © 1990-1991 Apple Computer, Inc.
  9. ** All rights reserved.
  10. */
  11.  
  12.  
  13.  
  14. /*****************************************************************************/
  15.  
  16.  
  17.  
  18. #include "CShell.h"                /* Get the CShell includes/typedefs, etc.    */
  19. #include "CShellCommon.h"        /* Get the stuff in common with rez.        */
  20. #include "CShell.protos"        /* Get the prototypes for CShell.            */
  21.  
  22. #ifndef __NOTIFICATION__
  23. #include <Notification.h>
  24. #endif
  25.  
  26. #ifndef __RESOURCES__
  27. #include <Resources.h>
  28. #endif
  29.  
  30. #ifndef __UTILITIES__
  31. #include "Utilities.h"
  32. #endif
  33.  
  34.  
  35.  
  36. /*****************************************************************************/
  37.  
  38.  
  39.  
  40. static Boolean        notifyActive = false;
  41. static pascal void    CancelNotify(NMRecPtr nmReqPtr);
  42. static NMRec        notifyTheUser = {
  43.     nil,        /* qLink */
  44.     nmType,        /* qType */
  45.     0,            /* nmFlags */
  46.     0L,            /* nmPrivate */
  47.     0,            /* nmReserved */
  48.     1,            /* nmMark */
  49.     nil,        /* nmIcon */
  50.     (Handle) -1,            /* nmSound */
  51.     nil,        /* nmStr */
  52.     nil,        /* nmResp */
  53.     0L            /* nmRefCon */
  54. };
  55.  
  56. extern RgnHandle    gCurrentCursorRgn;
  57.  
  58.  
  59.  
  60. /*****************************************************************************/
  61. /*****************************************************************************/
  62.  
  63.  
  64.  
  65. #pragma segment Main
  66. void    DoIdleTasks(void)
  67. {
  68.     DynamicBalloonHelp();
  69. }
  70.  
  71.  
  72.  
  73. /*****************************************************************************/
  74.  
  75.  
  76.  
  77. /* MyIdleProc
  78. **
  79. ** This routine gets either an updateEvt, an activateEvt, a nullEvent or an
  80. ** OSEvent.  The first time called it will get a nullEvent; this is its chance
  81. ** to set the sleep value and mouseRegion that will be passed to WaitNextEvent
  82. ** by the caller within the AEM.  After that it will also get events of the
  83. ** other types (which are lost if masked out by the AEM) and must do with them
  84. ** whatever is appropriate.
  85. */
  86.  
  87. #pragma segment Main
  88. pascal Boolean    MyIdleProcBoo(EventRecord *event, long *sleep, RgnHandle *mouseRgn)
  89. {
  90.     switch (event->what) {
  91.  
  92.         case updateEvt:
  93.         case activateEvt:
  94.         case kOSEvent:
  95.  
  96.             /* These events are passed by the AppleEvent manager to avoid
  97.                dropping while waiting for a reply or notification.  Every
  98.                procedure should handle these events in their idle procedure.
  99.                In this code, we simply dispatch these events back to the
  100.                main event loop handling code. */
  101.  
  102.             DoCursor(false, 0);
  103.             DoEvent(event);
  104.             break;
  105.  
  106.  
  107.         case nullEvent:
  108.  
  109.             /* The idle procedure is called once with the null event before
  110.                the loop begins.  This allows the application to alter sleep
  111.                time and mouseRgn to meet its own needs.  Since we're doing
  112.                nothing, set the cursor to a watch. */
  113.  
  114.             DoCursor(true, 'wait');
  115.  
  116.             *mouseRgn = gCurrentCursorRgn;
  117.             *sleep = 60;        /* This is just like the WaitNextEvent
  118.                                    sleeptime, so use the correct value for
  119.                                    your application.  It's better to use a
  120.                                    non-zero value here rather than zero,
  121.                                    as using zero really slows you down. */
  122.  
  123.             /* DoIdle(); */        /* Application's idle handling. */
  124.             break;
  125.  
  126.         default:
  127.             Alert(rErrorAlert, nil);
  128.             break;
  129.     }
  130.     return(false);
  131. }
  132.  
  133.  
  134.  
  135. /*****************************************************************************/
  136.  
  137.  
  138.  
  139. #pragma segment Main
  140. void    NotifyCancel(void)
  141. {
  142.     if (notifyActive) {
  143.         NMRemove((NMRecPtr)¬ifyTheUser);
  144.         notifyActive = false;
  145.     }
  146. }
  147.  
  148.  
  149.  
  150.  
  151. /*****************************************************************************/
  152.  
  153.  
  154.  
  155. #pragma segment Main
  156. void    NotifyUser(void)
  157. {
  158.     if (gInBackground) {
  159.         if (!notifyActive) {
  160.             notifyTheUser.nmIcon = GetResource('SICN', 128);
  161.             NMInstall(¬ifyTheUser);
  162.             notifyActive = true;
  163.         }
  164.     }
  165. }
  166.  
  167.  
  168.  
  169.